package com.kingyea.app.market;

import com.kingyea.mobilepolice.system.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

/**
 * @author cxc
 * @version v1.0.0
 * @description
 * @date Created in 2018.03.22 20:59
 */

public class Preconditions {

    public static <T> T checkNotNull(T reference, String code) {
        if (reference == null) throw new BusinessException(code);
        return reference;
    }

    public static String checkStringNotBlank(String str, String code) {
        if (!StringUtils.isNotBlank(str)) throw new BusinessException(code);
        return str;
    }

    public static <T> T checkIsNull(T reference, String code) {
        if (reference != null) throw new BusinessException(code);
        return reference;
    }

    public static void checkArgument(boolean expression, String code) {
        if (!expression) throw new BusinessException(code);
    }
}
